﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace BusinessClass.Business.ConfigEntity
{
    /// <summary>
    /// 配置总入口
    /// </summary>
    public class CenterConfig
    {
        [JsonProperty("ttf")]
        public string TtfFileName { get; set; }
        [JsonProperty("imgs")]
        public IEnumerable<ImgCuttingConfig> ImgCuttingConfigs { get; set; }
        [JsonProperty("rules")]
        public IEnumerable<RuleConfig> GenRuleConfigs { get; set; }

        public static CenterConfig FromJson(String json)
        {
            dynamic config = JsonConvert.DeserializeObject(json);
            CenterConfig obj = new CenterConfig();
            obj.TtfFileName = config.ttf;
            obj.ImgCuttingConfigs = ((JArray)config.imgs).Select(x => ImgCuttingConfig.FromJson(x.ToString()));
            obj.GenRuleConfigs = ((JArray)config.rules).Select(x => RuleConfig.FromJson(x.ToString()));
            return obj;
        }
        public override string ToString()
        {
            return JsonConvert.SerializeObject(this);
        }
    }
}
